package com.msb.mall.ware.controller;

import com.msb.common.utils.PageUtils;
import com.msb.common.vo.CommonPageReq;
import com.msb.common.vo.CommonResult;
import com.msb.mall.core.entity.ware.PurchaseDetailEntity;
import com.msb.mall.ware.service.PurchaseDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * @author leixu
 * @email xuleiwolf@163.com
 * @date 2024-04-19 20:31:49
 */
@RestController
@RequestMapping("ware/purchasedetail")
public class PurchaseDetailController {
    @Autowired
    private PurchaseDetailService purchaseDetailService;

    /**
     * 分页
     */
    @PostMapping("/page")
    public CommonResult page(@RequestBody CommonPageReq<Map<String, Object>> params) {
        PageUtils page = purchaseDetailService.queryPageCondition(params);

        return CommonResult.success(page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public CommonResult list(@RequestParam Map<String, Object> params) {
        PageUtils page = purchaseDetailService.queryPage(params);

        return CommonResult.success(null, page);
    }

    /**
     * 使用采购单获取采购需求详情
     */
    @GetMapping("/list/{purchase_id}")
    public CommonResult list(@PathVariable("purchase_id") Long purchaseId) {
        List<PurchaseDetailEntity> list = purchaseDetailService.listDetailByPurchaseId(purchaseId);

        return CommonResult.success(list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public CommonResult info(@PathVariable("id") Long id) {
        PurchaseDetailEntity purchaseDetail = purchaseDetailService.getById(id);

        return CommonResult.success(purchaseDetail);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public CommonResult save(@RequestBody PurchaseDetailEntity purchaseDetail) {
        purchaseDetailService.save(purchaseDetail);

        return CommonResult.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public CommonResult update(@RequestBody PurchaseDetailEntity purchaseDetail) {
        purchaseDetailService.updateById(purchaseDetail);

        return CommonResult.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public CommonResult delete(@RequestBody Long[] ids) {
        purchaseDetailService.removeByIds(Arrays.asList(ids));

        return CommonResult.success();
    }

}
